<template>
	<view>
		<view class="VerticalBox" :style="{ 'margin-top' : verticalNavTopS + 'rpx'}">
			<!-- :scroll-top="verticalNavTop" -->
			<scroll-view class="VerticalNav nav" scroll-y scroll-with-animation style="height:670rpx">
				<view class="cu-item" :class="index==tabCur?'cur':''" v-for="(item,index) in list" :key="index" @tap="TabSelect"
				 :data-id="index">
					{{item}}
				</view>
			</scroll-view>
			<scroll-view class="VerticalMain" scroll-y scroll-with-animation style="height:670rpx"
			 :scroll-into-view="'main-'+mainCur" @scroll="VerticalMain">
				<view class="" v-for="(item,index) in list" :key="index" :id="'main-'+index">
					<!-- <view class="cu-bar solid-bottom bg-white">
						<view class="action">
							<text class="cuIcon-title text-green"></text> {{item}}</view>
					</view> -->
					<view class="padding-left-48">
						<view class="right-text sel">智能推荐</view>
						<view class="right-text">电子政务</view>
						<view class="right-text">税务</view>
						<view class="right-text">电力</view>
						<view class="right-text">电信</view>
						<view class="right-text">保险</view>
						<view class="right-text">教育</view>
						<view class="right-text">证券</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				tabCur: 0,
				mainCur: 0,
				verticalNavTop: 0,
				verticalNavTopS:0,
				load: true
			};
		},
		created() {
			uni.showLoading({
				title: '加载中...',
				mask: true
			});
			let list = ['全部行业','常规行业','农林渔牧'];
			this.list = list;
			this.listCur = list[0];
			// 设置scroll-view距离头部导航栏的的高度
			let that=this
			uni.getSystemInfo({
			    success: (e) => {
					 const custom = uni.getMenuButtonBoundingClientRect()
					 let statusBar = e.statusBarHeight
					 that.verticalNavTopS = custom.bottom + custom.top - e.statusBarHeight
				}
			})
		},
		onReady() {
			uni.hideLoading()
		},
		methods: {
			TabSelect(e) {
				this.tabCur = e.currentTarget.dataset.id;
				this.mainCur = e.currentTarget.dataset.id;
				this.verticalNavTop = (e.currentTarget.dataset.id - 1) * 50
			},
			VerticalMain(e) {
				// #ifdef MP-ALIPAY
				   return false  //支付宝小程序暂时不支持双向联动 
				// #endif
				let that = this;
				let tabHeight = 0;
				if (this.load) {
					for (let i = 0; i < this.list.length; i++) {
						let view = uni.createSelectorQuery().select("#main-" + this.list[i].id);
						view.fields({
							size: true
						}, data => {
							this.list[i].top = tabHeight;
							tabHeight = tabHeight + data.height;
							this.list[i].bottom = tabHeight;
						}).exec();
					}
					this.load = false
				}
				let scrollTop = e.detail.scrollTop + 10;
				for (let i = 0; i < this.list.length; i++) {
					if (scrollTop > this.list[i].top && scrollTop < this.list[i].bottom) {
						this.verticalNavTop = (this.list[i].id - 1) * 50
						this.tabCur = this.list[i].id
						console.log(scrollTop)
						return false
					}
				}
			}
		},
	}
</script>

<style>
	.fixed {
		position: fixed;
		z-index: 99;
	}

	.VerticalNav.nav {
		width: 200upx;
		white-space: initial;
		background-color: rgba(219, 230, 255, 0.4);
	}

	.VerticalNav.nav .cu-item {
		width: 100%;
		text-align: center;
		/* background-color: rgba(219, 230, 255, 0.4); */
		margin: 0;
		border: none;
		height: 50px;
		position: relative;
	}

	.VerticalNav.nav .cu-item.cur {
		background-color: #ffffff;
	}

	.VerticalNav.nav .cu-item.cur::after {
		content: "";
		width: 8upx;
		height: 30upx;
		border-radius: 10upx 0 0 10upx;
		position: absolute;
		background-color: currentColor;
		top: 0;
		right: 0upx;
		bottom: 0;
		margin: auto;
	}

	.VerticalBox {
		display: flex;
	}

	.VerticalMain {
		background-color: #ffff;
		flex: 1;
	}
	.right-text{
		padding-top: 24rpx;
		font-size: 32rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #666666;
	}
	.sel{
		color: #24458E;
	}
</style>
